package com.groupbuying.currency.producer.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.groupbuying.currency.producer.domain.CurrencyPlatformLogDO;
import com.groupbuying.currency.producer.service.CurrencyPlatformLogService;
import com.groupbuying.currency.producer.utils.PageUtils;
import com.groupbuying.currency.producer.utils.Query;
import com.groupbuying.currency.producer.utils.R;

/**
 * 平台积分操作
 * 
 * @author zmlmagic
 * @email zmlmagic@163.com
 * @date 2019-10-14 15:05:24
 */
 
@RestController
@RequestMapping("/producer/currencyPlatformLog")
public class CurrencyPlatformLogController {
	@Autowired
	private CurrencyPlatformLogService currencyPlatformLogService;
	
	@GetMapping()
	@RequiresPermissions("producer:currencyPlatformLog:currencyPlatformLog")
	String CurrencyPlatformLog(){
	    return "producer/currencyPlatformLog/currencyPlatformLog";
	}
	
	@GetMapping("/list")
	@RequiresPermissions("producer:currencyPlatformLog:currencyPlatformLog")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<CurrencyPlatformLogDO> currencyPlatformLogList = currencyPlatformLogService.list(query);
		int total = currencyPlatformLogService.count(query);
		PageUtils pageUtils = new PageUtils(currencyPlatformLogList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("producer:currencyPlatformLog:add")
	String add(){
	    return "producer/currencyPlatformLog/add";
	}

	@GetMapping("/edit/{logId}")
	@RequiresPermissions("producer:currencyPlatformLog:edit")
	String edit(@PathVariable("logId") String logId,Model model){
		CurrencyPlatformLogDO currencyPlatformLog = currencyPlatformLogService.get(logId);
		model.addAttribute("currencyPlatformLog", currencyPlatformLog);
	    return "producer/currencyPlatformLog/edit";
	}
	
	/**
	 * 保存
	 */
	@PostMapping("/save")
	@RequiresPermissions("producer:currencyPlatformLog:add")
	public R save( CurrencyPlatformLogDO currencyPlatformLog){
		if(currencyPlatformLogService.save(currencyPlatformLog)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("producer:currencyPlatformLog:edit")
	public R update( CurrencyPlatformLogDO currencyPlatformLog){
		currencyPlatformLogService.update(currencyPlatformLog);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@RequiresPermissions("producer:currencyPlatformLog:remove")
	public R remove( String logId){
		if(currencyPlatformLogService.remove(logId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@RequiresPermissions("producer:currencyPlatformLog:batchRemove")
	public R remove(@RequestParam("ids[]") String[] logIds){
		currencyPlatformLogService.batchRemove(logIds);
		return R.ok();
	}
	
}
